<?xml version="1.0" encoding="ISO-8859-1" ?>

<html xmlns="http://www.w3.org/1999/xhtml" 
	  xmlns:h="http://java.sun.com/jsf/html" 
	  xmlns:f="http://java.sun.com/jsf/core"
	  xmlns:p="http://primefaces.org/ui"
	  xmlns:ui="http://java.sun.com/jsf/facelets">


<h:head>

</h:head> 

<h:body>
<ui:composition template="/template.xhtml">

	<ui:define name="conteudo">
			<h1><p:outputLabel value="#{msg.mensagem}"/></h1>
			<h:form enctype="multipart/form-data" styleClass="formMensagemForm"> 
				<p:growl id="messages" /> 
				<h:panelGrid columns="2" styleClass="painelMensagemForm">
					<h:outputLabel value="#{msg.para}" />		
					<h:panelGroup>
						<p:selectCheckboxMenu id="usuariosDest" label="#{msg.usuarios}" value="#{mensagemManagedBean.usuariosDest}" 
										  filter="true" filterMatchMode="contains" required="true" converter="UsuarioConverter" panelStyle="width: 600px; height : 200px;overflow: auto;">
							<f:selectItems value="#{mensagemManagedBean.usuarios}" var="usuario" 
										   itemLabel="#{usuario.tipo==1 ? (usuario.moderador.nome.concat(' - ').concat(usuario.moderador.matricula)) : 
										   			   (usuario.tipo==2 ? (usuario.professor.nome.concat(' - ').concat(usuario.professor.matricula)) : 
										   			   (usuario.aluno.nome.concat(' - ').concat(usuario.aluno.matricula)))}" 
										   itemValue="#{usuario}"  />
						</p:selectCheckboxMenu>
						<h:message for="usuariosDest" showDetail="false" showSummary="true" />
					</h:panelGroup>
				
					<h:outputLabel value="#{msg.titulo}" />
					<h:panelGroup>
						<p:inputText id="titulo" label="#{msg.titulo}" value="#{mensagemManagedBean.mensagem.titulo}" required="true">
							<f:validateLength minimum="1" maximum="60" />
						</p:inputText>
						<h:message for="titulo" showDetail="false" showSummary="true" />
					</h:panelGroup>
					
					<h:outputLabel value="#{msg.conteudo}" />
					<h:panelGroup>
						<p:inputTextarea id="conteudo" label="#{msg.conteudo}" value="#{mensagemManagedBean.mensagem.conteudo}" required="true"
										 maxlength="1024" counter="countCaracters"      
    									 counterTemplate="{0} #{msg.mensagemCaracter}." cols="40"/> 
						<h:message for="conteudo" showDetail="false" showSummary="true" />
						<p><h:outputLabel id="countCaracters" /></p>
					</h:panelGroup>		
					
					<h:outputLabel value="Anexo: " />
					<h:panelGroup>
						<p:fileUpload id="arquivo" value="#{mensagemManagedBean.arquivo}" mode="simple"  
									  auto="true" validator="#{formValidator.validateArquivo}"
									  multiple="false" required="false"/> 
						<h:message for="arquivo" showDetail="false" showSummary="true" />		  
					</h:panelGroup>

					<p:commandButton value="#{msg.enviar}"  oncomplete="confirmacao.hide()" 
								 action="#{mensagemManagedBean.insere}" update="messages" 
								 actionListener="#{mensagemManagedBean.anexar}" ajax="false"/>
				</h:panelGrid>
			</h:form>
	</ui:define>
</ui:composition>
	
</h:body> 
     
</html>